<template>
    <div>
        <el-row class="title">
            <h3>联系我们</h3>
        </el-row>
        <el-row>
            <el-form :inline="true" @submit.native.prevent>
                <el-form-item label="企业名称">
                    <el-input class="search-input" v-model="companyLike" placeholder="请输入企业名称" clearable @change="getData"></el-input>
                </el-form-item>
            </el-form>
        </el-row>
        <el-row>
            <el-table :data="dataList" border>
                <el-table-column prop="contactId" label="id" align="center"></el-table-column>
                <el-table-column prop="contactName" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phone" label="电话" align="center"></el-table-column>
                <el-table-column prop="email" label="邮箱" align="center"></el-table-column>
                <el-table-column prop="company" label="公司" align="center"></el-table-column>
                <el-table-column prop="message" label="留言" align="center"></el-table-column>
                <el-table-column label="提交时间" align="center">
                    <template slot-scope="scope">{{moment(scope.row.createTime).format('YYYY-MM-DD HH:mm:ss')}}</template>
                </el-table-column>
                <el-table-column label="操作" align="center" width="160px">
                    <template slot-scope="scope">
                        <el-button size="small" type="danger" @click="deleteDatas(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-row>
        <!-- 分页 -->
        <el-row>
            <el-col class="pagination">
                <el-pagination @current-change="currentChange" :current-page="pageId" :page-size="pageSize" layout="total, prev, pager, next" :total="count">
                </el-pagination>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import {
    getContactLists,
    deleteContactById
} from '@/api/api'
export default {
    data: function() {
        return {
            dataList: [],
            pageId: 1,
            pageSize: 10,
            count: 0,
            companyLike: ''
        }
    },
    created: function() {
        this.pageId = parseInt(this.$route.query.page) || 1;
        this.getData();
    },
    methods: {
        getData: function() {
            getContactLists({
                params: {
                    pageId: this.pageId,
                    pageSize: this.pageSize,
                    companyLike: this.companyLike
                }
            }).then(res => {
                console.log(res)
                this.dataList = res.list;
                this.count = res.count;
            })
        },
        deleteDatas: function(index, row) {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                deleteContactById(row.contactId).then(res => {
                    this.getData();
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        currentChange: function(val) {
            this.$router.push('?page=' + val);
            this.pageId = val;
            this.getData();
        }
    }
}
</script>
<style scoped lang="scss">
.title {
    font-size: 12px;
    margin-bottom: 5px;
    h3 {
        display: inline-block;
        padding: 5px 0;
        margin: 0;
        font-weight: normal;
        color: #000;
        border-bottom: 2px solid #000;
    }
}
.poster {
    max-width: 100%;
}

.poster-thumb {
    max-width: 100%;
}
</style>